package com.xoms.admin.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xoms.admin.controller.res.ListResult;
import com.xoms.admin.controller.res.bean.RProDepositBean;
import com.xoms.admin.controller.res.bean.RProDepositDetailBean;
import com.xoms.admin.controller.springmvc.req.GetDepositDetailParam;
import com.xoms.admin.controller.springmvc.req.GetProDepositsParam;
import com.xoms.admin.model.AccountBean;
import com.xoms.admin.service.ProDepositService;
import com.xoms.admin.service.exception.ServiceException;
import com.xoms.admin.service.res.PageResult;
import com.xoms.util.NumUtil;

@Component
public class ProDepositController {
	
	@Autowired
	ProDepositService proDespositServiceImpl;
	
	/**
	 * 获取寄存列表
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RProDepositBean> getDeposits(GetProDepositsParam param, HttpServletRequest request,
			HttpServletResponse response) {
		
		ListResult<RProDepositBean> result = new ListResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			int page = NumUtil.toInt(param.getPage(), 0);
			int PageSize = NumUtil.toInt(param.getPageSize(), 20);
			String startTime = param.getStartTime();
			String endTime = param.getEndTime();
			String storeId = param.getStoreHouseId();// 仓库id
			
			// 获取寄存列表
			PageResult<RProDepositBean> resData = proDespositServiceImpl.getDeposits(account, page, PageSize, startTime,
					endTime, storeId);
			if (resData != null) {
				result.setData(resData.getData());
				result.setTotalSize(resData.getCount());
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 获取寄存详情列表
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RProDepositDetailBean> getDepositDetails(GetDepositDetailParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ListResult<RProDepositDetailBean> result = new ListResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			String did = param.getDid();
			String key = param.getKey();
			int page = NumUtil.toInt(param.getPage(), 0);
			int PageSize = NumUtil.toInt(param.getPageSize(), 20);
			int paging = NumUtil.toInt(param.getPaging(), 1);// 是否分页
			
			// 查询详情列表
			PageResult<RProDepositDetailBean> resData = proDespositServiceImpl.getDepositDetails(account, key, page, PageSize,
					did, paging);
			if (resData != null) {
				result.setData(resData.getData());
				result.setTotalSize(resData.getCount());
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}

}
